﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Xml;

namespace Tum.CollabXT.VModellXT.Tailoring
{
    public class ProcessModule
    {
        private ProcessModule() { }

        public static ProcessModule Create(string pmNodeId, XmlDocument modelDoc)
        {
            XmlNode pmNode = modelDoc.SelectSingleNode("//Vorgehensbaustein[@id ='" + pmNodeId + "']");
            ProcessModule pm = new ProcessModule();

            pm.Id = pmNodeId;
            pm.Name = pmNode.SelectSingleNode("Name").InnerText;

            return (pm);
        }


        /// <summary>
        /// Id of the Module
        /// </summary>
        public string Id
        {
            get;
            private set;
        }

        /// <summary>
        /// Name of the Module
        /// </summary>
        public string Name
        {
            get;
            private set;
        }
    }

    public class ProcessExecutionModule
    {
        private ProcessExecutionModule() { }


        public static ProcessExecutionModule Create(string pmNodeId, XmlDocument modelDoc)
        {
            XmlNode pmNode = modelDoc.SelectSingleNode("//Ablaufbaustein[@id ='" + pmNodeId + "']");
            ProcessExecutionModule pm = new ProcessExecutionModule();

            pm.Id = pmNodeId;
            pm.Name = pmNode.SelectSingleNode("Name").InnerText;

            List<ProcessExecutionModuleSpecification> pemSpecsList = new List<ProcessExecutionModuleSpecification>();
            foreach (XmlAttribute curPemSpecIdAttr in pmNode.SelectNodes("Ablaufbausteinpunkt/AblaufbausteinspezifikationRef/@link"))
                pemSpecsList.Add(ProcessExecutionModuleSpecification.Create(curPemSpecIdAttr.Value, modelDoc));
            pm.ProcessExecutionModuleSpecifications = pemSpecsList.ToArray();

            return (pm);
        }


        /// <summary>
        /// Id of the Module
        /// </summary>
        public string Id
        {
            get;
            private set;
        }

        /// <summary>
        /// Name of the Module
        /// </summary>
        public string Name
        {
            get;
            private set;
        }

        public ProcessExecutionModuleSpecification[] ProcessExecutionModuleSpecifications
        {
            get;
            private set;
        }
    }

    public class ProcessExecutionModuleSpecification
    {
        private ProcessExecutionModuleSpecification() { }

        public static ProcessExecutionModuleSpecification Create(string pmNodeId, XmlDocument modelDoc)
        {
            XmlNode pmNode = modelDoc.SelectSingleNode("//Ablaufbausteinspezifikation[@id ='" + pmNodeId + "']");
            ProcessExecutionModuleSpecification pm = new ProcessExecutionModuleSpecification();

            pm.Id = pmNodeId;
            pm.Name = pmNode.SelectSingleNode("Name").InnerText;

            return (pm);
        }


        /// <summary>
        /// Id of the Specification
        /// </summary>
        public String Id
        {
            get;
            private set;
        }

        /// <summary>
        /// Name of the Specification
        /// </summary>
        public string Name
        {
            get;
            private set;
        }
    }
}
